<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html lang="zh-cn">
<head>
	<meta charset="UTF-8">
	<title>设置服务开放时间</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="wap-font-scale" content="no">
	<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1,user-scalable=no">
	<meta name="keywords" content="">
	<meta name="description" content="">
	<link rel="stylesheet" type="text/css" href="${ctx}/resources/datePicker/css/public.css">

	<!-- 引入样式和js文件 -->
	<link rel="stylesheet" type="text/css" href="${ctx}/resources/datePicker/css/mobileSelect.css">

	<script src="${ctx}/resources/datePicker/js/mobileSelect.js" type="text/javascript"></script>
	<script src="${ctx}/resources/datePicker/js/jquery1.8.3.min.js" type="text/javascript"></script>

	<style type="text/css">
		#trigger3 span:last-child tt{ color:#fff}
		#trigger3 span tt{ font-size:14px; line-height:24px; color:#000}
	</style>

</head>
<body>


<div class="contain">
	<div class="fixWidth">
		<div class="nav">
			<h1>设定开放服务时间</h1>
		</div>
		<div type="text" id="calendarId" value="${myCalendar.id}" style="display: none"></div>
		<div class="title">
			<label>标题</label>
			<input   id="title" value="${myCalendar.title}"  type="text" />
		</div>
		<div class="demo">
			<div id="trigger3">选择开始时间</div>
			<div id="trigger4">选择结束时间</div>
		</div>


	</div>
	<div>
		<button  href="javascript:;" onClick="back()">返回上一页</button>
		<button onclick="submitCalendar()">确定</button>
	</div>

</div>



<script type="text/javascript">
	var numArr1=['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24'];
	var numArr2=['00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50','51','52','53','54','55','56','57','58','59','60'];
	var mobileSelect3 = new MobileSelect({
		trigger: '#trigger3',
		title: '选择时间',
		wheels: [
			{data: numArr1},
			{data: numArr2},
			{data: numArr2}
		],
		position:[0, 0, 0],
		//transitionEnd:function(indexArr, data){
		//    console.log(data);
		//},
		callback:function(indexArr, data){
			var lastElementIndex = data.length-1;
			data[lastElementIndex] = data[lastElementIndex].replace(":","")
			$("#trigger3").html(data);

		}
	});

	var mobileSelect4 = new MobileSelect({
		trigger: '#trigger4',
		title: '选择时间',
		wheels: [
			{data: numArr1},
			{data: numArr2},
			{data: numArr2}
		],
		position:[0, 0],
		//transitionEnd:function(indexArr, data){
		//    console.log(data);
		//},
		callback:function(indexArr, data){
			var lastElementIndex = data.length-1;
			data[lastElementIndex] = data[lastElementIndex].replace(":","")
			$("#trigger4").html(data);

		}
	});
	$(document).ready(function(){

		var initStartTime = '${myCalendar.starttime}';
		var initEndTime = '${myCalendar.endtime}'
		var startTimeArray = new Array();
		var endTimeArray  = new Array();
		if (initStartTime != undefined && initStartTime != ''){
			$("#trigger3").html(initStartTime);
			startTimeArray = initStartTime.split(":");
			mobileSelect3.locatePosition(0,startTimeArray[0]-1);
			mobileSelect3.locatePosition(1,startTimeArray[1])
			mobileSelect3.locatePosition(2,startTimeArray[2])
		}

		if (initEndTime != undefined && initEndTime != ''){
			$("#trigger4").html(initEndTime);
			endTimeArray = initEndTime.split(":");
			mobileSelect4.locatePosition(0,endTimeArray[0]-1);
			mobileSelect4.locatePosition(1,endTimeArray[1])
			mobileSelect4.locatePosition(2,endTimeArray[2])
		}


	});

	function  back(){
		top.location="${ctx}/wechat/hunter/myCalendar/myCalendar.page";
	}

	function submitCalendar(){
		var title= $('#title').val();
		var startTime =  $('#trigger3').text();
		var endTime =$('#trigger4').text();

		if(title == ''){
			alert("请填写标题");
			return  false;
		}
		if (startTime == '选择开始时间'){
			alert("请选择开始时间");
			return false;
		}
		if (endTime == '选择结束时间'){
			alert("请选择结束时间")
			return false;
		}
		var params = {
			'title': title,
			'starttime': startTime,
			'endtime': endTime,
			'dateKey': '${dateTime}',
			'id': '${myCalendar.id}'
		}
		$.ajax({
			url: '${ctx}/wechat/hunter/myCalendar/saveOrUpdate',
			type: 'POST',
			data: params,
			success: function (data){
				if(data.code == "0"){
					alert(data.msg)
				}
				if(data.code == '1'){
					alert(data.msg)
					top.location="${ctx}/wechat/hunter/myCalendar/myCalendar.page";
				}

			},
			error: function(data){
				alert("服务出现异常，请稍后再试!");
			}
		})
	}



</script>

</body>
</html>